package com.xmcowell.sportpacemaster.utils;

import android.text.format.Time;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * 时间
 * Created by xmsz on 2016/11/18.
 */

public class TimeUtil {

    /**
     * 将Date时间转换为字符串 yyyy-MM-dd
     *
     * @param dateDate
     * @param
     * @return
     */
    public static String dateToStr(Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm dd MM yyyy", Locale.ENGLISH);
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    /**
     * 获取英语时间
     *
     * @return
     */
    public static String englishDateNow() {
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        String m = "";
        String date = "";
        switch (month + 1) {
            case 1://1月
                m = "Jan";
                break;
            case 2://2月
                m = "Feb";
                break;
            case 3://3月
                m = "Mar";
                break;
            case 4://4月
                m = "Apr";
                break;
            case 5://5月
                m = "May";
                break;
            case 6://6月
                m = "Jun";
                break;
            case 7://7月
                m = "Jul";
                break;
            case 8://8月
                m = "Aug";
                break;
            case 9://9月
                m = "Sep";
                break;
            case 10://10月
                m = "Oct";
                break;
            case 11://11月
                m = "Nov";
                break;
            case 12://12月
                m = "Dec";
                break;
            default:
                m = month + "";
                break;
        }
        String h = hour < 10 ? "0" + hour : "" + hour;
        String min = minute < 10 ? "0" + minute : "" + minute;
        date = h + ":" + min + "  " + day + " " + m + " " + year;
        return date;
    }

    // a integer to xx:xx:xx
    public static String secToTime(int time) {
        String timeStr = null;
        int hour = 0;
        int minute = 0;
        int second = 0;
        if (time <= 0)
            return "00:00";
        else {
            minute = time / 60;
            if (minute < 60) {
                second = time % 60;
                timeStr = unitFormat(minute) + ":" + unitFormat(second);
            } else {
                hour = minute / 60;
                if (hour > 99)
                    return "99:59:59";
                minute = minute % 60;
                second = time - hour * 3600 - minute * 60;
                timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
            }
        }

        return timeStr;
    }

    public static String secToTime2(int time) {
        String timeStr = null;
        int hour = 0;
        int minute = 0;
        int second = 0;
        if (time <= 0)
            return "00:00";
        else {
            minute = time / 60;
            second = time % 60;
            timeStr = unitFormat(minute) + ":" + unitFormat(second);
        }

        return timeStr;
    }

    public static String secToTime3(int time) {
        String timeStr = null;
        int hour = 0;
        int minute = 0;
        int second = 0;
        if (time <= 0)
            return "00'00";
        else {
            minute = time / 60;
            second = time % 60;
            timeStr = unitFormat(minute) + "\'" + unitFormat(second) + "\"";
        }

        return timeStr;
    }


    public static String unitFormat(int i) {
        String retStr = null;
        if (i >= 0 && i < 10)
            retStr = "0" + Integer.toString(i);
        else
            retStr = "" + i;
        return retStr;
    }

    //把日期转为字符串
    public static String ConverToString2(Date date) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (df == null || date == null)
            return "";
        return df.format(date);
    }
}
